﻿using BepInEx;
using BepInEx.Configuration;
using System.IO;
using UnityEngine;

namespace HappyStudent.CfgMain
{
    /// <summary>
    /// 检查更新
    /// </summary>
    public partial class CfgMain
    {
        public static string GameAssemblyPath { get; private set; }
        public static string ConfigPath { get; private set; }

        private static string ModPath;

        public static bool IsUpdated;
        void UpdateCheck()
        {
            GameAssemblyPath = Path.Combine
                    (
                    Paths.GameRootPath,
                    "StudentAge_Data",
                    "Managed",
                    "Assembly-CSharp.dll"
                    );
            ConfigPath = Path.Combine(
                   Paths.ConfigPath,
                   "CfgMain.cfg"
                   );
            ModPath = Path.Combine(
                Paths.PluginPath,
                "HappyStudent.dll"
                );
            var hash = (File.GetLastWriteTime(GameAssemblyPath).Ticks & File.GetLastWriteTime(ModPath).Ticks);
            var cdf = new ConfigDefinition("CfgMain", "Hash");
            long def = 0;
            long loadhash = Config.Bind(cdf, def).Value;
            IsUpdated = hash != loadhash; 
            Debug.LogWarning($"UpdateCheck {loadhash} {hash} {IsUpdated}");
            if (IsUpdated)
            {
                Config.Remove(cdf);
                Config.Bind(cdf, hash);
              
            }
        }
    }
}
